#pragma once
#include "IGeom.h"
#include "ICamera.h"

/**
    Irrlicht Engines BSP Loader
*/
class IrrBSPGeomLoader : public IGeomLoader
{
public:
    IrrBSPGeomLoader(void);

    /** Load a Map */
    IGeom* LoadGeom( const std::string &GeomFile );
public:
    virtual ~IrrBSPGeomLoader(void);
};


namespace irr {

    namespace scene {
        class ISceneManager;
        class IAnimatedMesh;
    };
};

/**
    Irrlicht BSP Map
*/
class IrrCamera;
class IrrBSPGeom : public IGeom
{
public:
    IrrBSPGeom(irr::scene::ISceneManager* scene) : m_valid(false), m_IrrMesh(NULL), 
            m_IrrNode(NULL), m_IrrSceneMng(scene) {};

    /** Render the map */
    void        Render( IRender* r, ICamera* cam );

    /** Get map type */
    Geom_t      GetType() { return GF_BSP; };

    /** Init the map */
    void        Init();

    /** Free the Map */
    void        FreeGeom();

    /** Set Mesh */
    void SetMesh( irr::scene::IAnimatedMesh* mesh ) { 
        if( mesh ) { 
                     m_IrrMesh = mesh;
                     m_valid = true; 
                   } 
    };

    /** Set Scene Node */
    void SetSceneNode ( irr::scene::ISceneNode* node ) {
        if ( node ) {
            m_IrrNode = node;
        }
    };

    /** Get the Mesh */
    irr::scene::IAnimatedMesh* GetMesh() { return m_IrrMesh; };
    /** Get the Scene node */
    irr::scene::ISceneNode*    GetNode() { return m_IrrNode; };

    /** Map loaded successfully */
    bool IsValid() { return m_valid; };

    virtual ~IrrBSPGeom(){};

private:
    irr::scene::IAnimatedMesh*  m_IrrMesh;          // Irrlicht stores the BSP in a single frame mesh
    irr::scene::ISceneNode*     m_IrrNode;          // Irrlicht scene Node
    irr::scene::ISceneManager*  m_IrrSceneMng;      // Irrlicht Scene Mng
    
    IrrCamera*                    m_Camera;           // scene camera
    bool    m_valid;                                // Test to see if the BSP loaded
    
};